// src/utils/axios.js
import axios from 'axios';

const http = axios.create({
  baseURL: '/', // 设置基础URL
  timeout: 5000,
});

// 请求拦截器
http.interceptors.request.use(
  config => {
    // 如果有token，添加到请求头
    const token = localStorage.getItem('token');
    if (token) {
      config.headers.Authorization = `Bearer ${token}`;
    }
    return config;
  },
  error => {
    return Promise.reject(error);
  }
);

// 响应拦截器
http.interceptors.response.use(
  response => {
    // 直接返回响应数据
    return response.data;
  },
  error => {
    return Promise.reject(error);
  }
);

export default http;